gh-150880: Normalize Windows scandir wildcard paths#152906
Merged
Merged
Conversation
|
Thanks @zainnadeem786 for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-152963 is a backport of this pull request to the 3.15 branch. |
|
GH-152964 is a backport of this pull request to the 3.14 branch. |
|
GH-152965 is a backport of this pull request to the 3.13 branch. |
zooba
pushed a commit
that referenced
this pull request
Jul 3, 2026
GH-152906) (GH-152965) gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) This ensures that we don't turn a "valid" path with trailing spaces into an invalid path with embedded spaces. (cherry picked from commit 1b4135a) Co-authored-by: Zain Nadeem <zainnadeemzainnadeem80@gmail.com>
zooba
pushed a commit
that referenced
this pull request
Jul 3, 2026
GH-152906) (GH-152964) gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) This ensures that we don't turn a "valid" path with trailing spaces into an invalid path with embedded spaces. (cherry picked from commit 1b4135a) Co-authored-by: Zain Nadeem <zainnadeemzainnadeem80@gmail.com>
zooba
pushed a commit
that referenced
this pull request
Jul 3, 2026
GH-152906) (GH-152963) gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) This ensures that we don't turn a "valid" path with trailing spaces into an invalid path with embedded spaces. (cherry picked from commit 1b4135a) Co-authored-by: Zain Nadeem <zainnadeemzainnadeem80@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows,
os.listdir()andos.scandir()append a wildcard before callingFindFirstFileW().For paths with a trailing space, this changes the path from a final-component trailing-space case into an internal path component, so Windows no longer trims the space. This makes
listdir()andscandir()behave differently from APIs such asopen(),os.stat(), andos.path.exists().This PR normalizes non-extended Windows base paths with
GetFullPathNameW()before appending the wildcard used for enumeration.Extended paths beginning with
\\?\continue to bypass normalization.Changes
listdir()andscandir().DirEntry.pathconstruction behavior.Tests
Close #150880